package cn.ren.cloud.service.impl;

import cn.ren.cloud.service.ITokenService;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.UUID;
import java.util.concurrent.TimeUnit;

/**
 * @author 23508
 */
@Service
public class TokenServiceImpl implements ITokenService {

    private final RedisTemplate<Object, Object> redisTemplate;

    public TokenServiceImpl(RedisTemplate<Object, Object> redisTemplate) {
        this.redisTemplate = redisTemplate;
    }

    /**
     * 获取Token码
     *
     * @param courseId 课程ID
     * @return Token码
     */
    @Override
    public String getCreateToken(Long courseId) {
        Long loginId = 1L;
        String key = loginId + ":" + courseId;
        String value = UUID.randomUUID().toString();
        redisTemplate.opsForValue().set(key, value, 600000, TimeUnit.MILLISECONDS);
        return value;
    }
}
